// eslint.config.js
import js from "@eslint/js"
import globals from "globals"
import pluginVue from "eslint-plugin-vue"
import vueParser from "vue-eslint-parser"
import tseslint from "typescript-eslint"
import { defineConfig } from "eslint/config"
import prettierPlugin from "eslint-plugin-prettier"
import prettierConfig from "eslint-config-prettier"

export default defineConfig([
  /* ---------- 忽略项（替代 .eslintignore） ---------- */
  { ignores: ["node_modules", "dist"] },

  /* ---------- 官方 JS 推荐规则 ---------- */
  js.configs.recommended,

  /* ---------- Vue 推荐规则（是数组，必须展开到顶层） ---------- */
  ...pluginVue.configs["flat/recommended"],

  /* ---------- TypeScript 推荐规则（含类型检查，也是数组） ---------- */
  ...tseslint.configs.recommendedTypeChecked,

  /* ---------- 通用语言选项 / 插件 ---------- */
  {
    files: ["**/*.{js,ts,vue}"],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: { ...globals.browser, ...globals.node },
    },
    plugins: {
      "@typescript-eslint": tseslint.plugin,
      vue: pluginVue,
      prettier: prettierPlugin,
    },
    rules: {
      "prettier/prettier": "warn", // ✅ 明确开启 Prettier 警告提示
    },
  },

  /* ---------- TypeScript / Vue 文件类型支持 ---------- */
  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        project: "./tsconfig.eslint.json",
      },
    },
  },
  {
    files: ["**/*.vue"],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: tseslint.parser,
        project: "./tsconfig.eslint.json",
        extraFileExtensions: [".vue"],
      },
    },
  },

  /* ---------- Prettier 兼容配置 ---------- */
  prettierConfig,
])
